//lambda表达式---捕获表 (捕获lambda表达式外部变量的值)
#include <iostream>
#include <typeinfo>
using namespace std;

int a = 10;

class Y {
public:
	void foo(int c = 30) {
		cout << "--------------------空[]-----------" << endl;
		[](int d = 40) {
			cout << "a=" << a << endl;
			cout << "b=" << b << endl;
			//cout << "c=" << c << endl;//error
			cout << "d=" << d << endl;
			//cout << "e=" << e << endl;//error
		}();
		/*
			class X{
			public:
				void operator()(int d = 40){
					cout << "a=" << a << endl;
					cout << "b=" << b << endl;
				//	cout << "c=" << c << endl;//error
					cout << "d=" << d << endl;
					//cout << "e=" << e << endl;//error

				}

			};
			X{}();
		*/
		cout << "--------------------空[]-----------" << endl;
		//捕获外部变量的值
		[c](int d = 40) {cout << "c=" << c << endl; };
		/*
			class XX{
			public:
				XX(int m):c(m){}//这里的c并不是foo函数的形参，而是XX类的一个成员变量
				void operator()(int d=40){
					cout << "C=" << c << endl;//这里的c并不是foo函数的形参，而是XX类的一个成员变量
				}
			pivate:
				const int c;//这里的c并不是foo函数的形参，而是XX类的一个成员变量

			}
			XX{c}();//这里的c是foo函数的形参c XX(c).operator()(c);
		*/
		cout << "--------------------[&c]-----------" << endl;
		[&c](int d = 40) {cout << "c=" << ++c << endl; }();
		cout << "--------------------[this]-----------" << endl;
		[this](int d = 40) {cout << "e=" << e << endl; }();


	}
private:
	static int b;
	int e;
};
int Y::b = 20;

int main(void) {
	Y y;
	y.foo();
	return 0;
}